package com.evil.application.strategy.reporting;

import com.evil.application.enums.reporting.ReportingTypeEnum;
import com.evil.application.pojo.dto.reporting.ApplicationReportingDTO;
import com.evil.application.pojo.dto.reporting.data.ReportingDataRespDTO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.search.aggregations.Aggregations;
import org.springframework.stereotype.Service;

/**
 * 报表类型-柱状表
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Slf4j
@Service
@AllArgsConstructor
public class ReportingDataColumnarChartImpl implements ReportingDataChart {

    @Override
    public ReportingTypeEnum type() {
        return ReportingTypeEnum.COLUMNAR_CHART;
    }

    /**
     * 统计
     *
     * @param reportingDTO reportingDTO
     * @param aggregations aggregations
     * @return ReportingDataRespDTO
     */
    @Override
    public ReportingDataRespDTO calculation(ApplicationReportingDTO reportingDTO, Aggregations aggregations) {
        ReportingDataRespDTO reportingDataRespDTO = new ReportingDataRespDTO(reportingDTO.getReportingKey());
        reportingDataRespDTO.setReportingSeries(this.series(reportingDTO, aggregations));
        return reportingDataRespDTO;
    }
}
